//
//  BFMenuView.m
//  BFoodSystem
//
//  Created by 浙江择富 on 2018/3/13.
//  Copyright © 2018年 陈名正. All rights reserved.
//

#import "BFMenuView.h"
#import "BFNewsCenterController.h"

@interface BFMenuView()

/** 消息按钮*/
@property (nonatomic,strong) UIButton *messageBtn;
/** 按钮*/
@property (nonatomic,strong) UIButton *btn;

@end

@implementation BFMenuView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
  
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(10, 10, 180, 30);
        //    button.backgroundColor = [UIColor yellowColor];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        
        [button setTitle:[NSString stringWithFormat:@"%@的店", [BFUserSignelton shareBFUserSignelton].mobile] forState:UIControlStateNormal];
        
        [button setImage:[UIImage imageNamed:@"icon_back_r"] forState:UIControlStateNormal];
        [button setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, button.currentImage.size.width)];
        [button setImageEdgeInsets:UIEdgeInsetsMake(0,button.size.width-15, 0, 0)];
        [self addSubview:button];
        [button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        self.btn = button;
        
        
        UIButton *infoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [infoBtn setImage:[UIImage imageNamed:@"iconInformation"] forState:UIControlStateNormal];
        [infoBtn addTarget:self action:@selector(infoBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:infoBtn];
        
        self.messageBtn = infoBtn;
    }
    
    return self;
}

#pragma mark -----消息事件
-(void)btnClick:(UIButton *)btn{
    BFLog (@"点击了按钮");
}
//详情事件
- (void)infoBtnClick:(UIButton *)btn{
//    BFLog(@"点击了消息按钮");
    BFNewsCenterController *newsVC = [BFNewsCenterController new];
    //取出根视图控制器
    UITabBarController *tabBarVc = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
    //取出当前选中的导航控制器
    UINavigationController *Nav = [tabBarVc selectedViewController];
    [Nav pushViewController:newsVC animated:YES];

    
    
}

- (void)layoutSubviews{
    [super layoutSubviews];
 
    
    [self.messageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-15);
        make.centerY.equalTo(self.btn);
        make.size.mas_equalTo(self.messageBtn.currentImage.size);
    }];
}
@end
